import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
// import Index from "@/views/Index";
// import Home from "@/views/home/Home";
// import Archives from "@/views/archives/Archives";
// import Blog from "@/views/blog/Blog";
// import Tag from "@/views/tag/Tag";
// import Category from "@/views/category/Category";
// import Moments from "@/views/moments/Moments";
// import Friends from "@/views/friends/Friends";
// import About from "@/views/about/About";
// import Login from "@/views/Login";
// import Drop from "@/components/index/Drop"
Vue.use(VueRouter)

const routes = [{
    path: '/login',
    component: () => import('@/views/Login'),
    meta: {
        title: '登录'
    }
},
{
    path: '/drop',
    component: () => import('@/components/index/Drop'),
    meta: {
        title: '退出'
    }
},
{
    path: '/register',
    component: () => import('@/components/zhuce'),
    meta: {
        title: '注册'
    }
},
{
    path: '/',
    component: () => import('@/views/Index'),
    redirect: '/home',
    children: [{
        path: '/home',
        name: 'home',
        component: () => import('@/views/home/Home'),
        meta: {
            title: '首页'
        }
    },
    {
        path: '/archives',
        name: 'archives',
        component: () => import('@/views/archives/Archives'),
        meta: {
            title: '归档'
        }
    },
    {
        path: '/blog/:id',
        name: 'blog',
        component: () => import('@/views/blog/Blog'),
        meta: {
            title: '博客'
        }
    },
    {
        path: '/tag/:name',
        name: 'tag',
        component: () => import('@/views/tag/Tag'),
        meta: {
            title: '标签'
        }
    },
    {
        path: '/category/:name',
        name: 'category',
        component: () => import('@/views/category/Category'),
        meta: {
            title: '分类'
        }
    },
    {
        path: '/moments',
        name: 'moments',
        component: () => import('@/views/moments/Moments'),
        meta: {
            title: '动态'
        }
    },
    {
        path: '/friends',
        name: 'friends',
        component: () => import('@/views/friends/Friends'),
        meta: {
            title: '友人帐'
        }
    },
    {
        path: '/about',
        name: 'about',
        component: () => import('@/views/about/About'),
        meta: {
            title: '关于我'
        }
    }
    ]
}
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

//挂载路由守卫
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        if (store.state.siteInfo.webTitleSuffix) {
            document.title = to.meta.title + store.state.siteInfo.webTitleSuffix
        } else {
            document.title = to.meta.title
        }
    }
    next()
})

export default router